package com.example.springbootdemo.impot;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.*;

@Configuration
// 包扫描方式只用来批量导入自己写的bean，需要扫描的类上有相应的注解
@ComponentScan("com.example.springbootdemo.impot")
@ComponentScan(value = "com.example.springbootdemo.demos.web",
        useDefaultFilters = false,
        includeFilters = {@ComponentScan.Filter(type = FilterType.CUSTOM,value = MyScanFilter.class)})
// @Import: 批量导入bean、复杂导入指定bean  都可导入第三方bean
// @Import({MySelectImport.class, MyImportBeanDefinitionRegistrar.class})
public class MainConfig {


    // @Bean 方式导入bean与xml配置中导入方式一致，可以简单导入bean或第三方bean
    @Bean
    //@Lazy
    @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public Person person(){
        System.out.println("******************** 创建了person *************");
        Person user = new Person();
        user.setName("xxx");
        user.setAge(12);
        return user;
    }

    /*@Bean
    public MyFactoryBean myFactoryBean(){
        return new MyFactoryBean();
    }*/


    // 条件按需加载bean，autoconfigure 包内有更灵活的注解 @ConditionalOnProperty
    @Conditional(MyCondition.class)
    @Bean("winImportDemo")
    public MyImportDemo myImportDemo(){
        return new MyImportDemo();
    }
}
